package com.ly.report_ah.dao.master;

import com.ly.report_ah.entity.master.SmpSummary;
import com.ly.report_ah.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface ReportMapper {

    //    @Select("select \n" +
//            "       s.company_name AS companyName, \n" +
//            "       s.sub_name,\n" +
//            "       s.psr_name,\n" +
//            "       s.psr_id,\n" +
//            "       s.psr_type,\n" +
//            "       to_char(wm_concat(s.judge_type)) judge_type,\n" +
//            "       to_char(wm_concat(s.judge_source)) judge_source,\n" +
//            "       to_char(wm_concat(s.data_source)) data_source,\n" +
//            "       s.voltage,\n" +
//            "       to_char(wm_concat(s.judge_id)) judge_id,\n" +
//            "       s.obj_id,\n" +
//            "       s.company_id\n" +
//            "  from smp_summary202012 s\n" +
//            " where s.psr_type = #{psr_type}\n" +
//            "   and s.voltage = #{voltage}\n" +
//            " and s.company_id=#{company_id}\n" +
//            " group by s.obj_id,\n" +
//            "          s.company_id,\n" +
//            "          s.voltage,\n" +
//            "          s.psr_id,\n" +
//            "          s.psr_type,\n" +
//            "          s.company_name,\n" +
//            "          s.sub_name,\n" +
//            "          s.psr_name")
    List<SmpSummary> getSummaryData(@Param("company_id") String company_id, @Param("psr_type") String psr_type, @Param("voltage") String voltage);

    @Select("select JUDGE_TYPE, count(1) AS count from smp_summary202012 where company_id=#{company_id} and psr_type = #{psr_type} and voltage = #{voltage} group by judge_type ")
    List<StatisticsVo> getStatisticsMap(@Param("company_id") String company_id, @Param("psr_type") String psr_type, @Param("voltage") String voltage);


    int updateLmsTrandetailCompany(@Param("companyId") String companyId, @Param("companyName") String companyName);

    int updateLmsLinedetailCompany(@Param("companyId") String companyId, @Param("companyName") String companyName);

    int updateLmsDistdetailCompany(@Param("companyId") String companyId, @Param("companyName") String companyName);

    int updateDatWirepoleOledCompany(@Param("companyId") String companyId, @Param("companyName") String companyName);

    int updateDatWirepoleWindCompany(@Param("companyId") String companyId, @Param("companyName") String companyName);

    int updateDatInsulatorCompany(@Param("companyId") String companyId, @Param("companyName") String companyName);

    int updateLltweightLossTranCompany(@Param("companyId") String companyId, @Param("companyName") String companyName);

    int updateLltweightLossLineCompany(@Param("companyId") String companyId, @Param("companyName") String companyName);

    int insertSummar(@Param("companyId") String companyId);

    @Select("select * from ODS_DAT_OLDWIREPOLE202012 where obj_id = #{objId}")
    List<Map<String, Object>> getOldWirePoleByObjId(@Param("objId") String objId);

    @Select("select * from ODS_DAT_WINDWIREPOLE202012 where obj_id = #{objId} and REGION_MAX_CODE = #{regionMaxCode}")
    List<Map<String, Object>> getWindWirePoleByObjId(@Param("objId") String objId, @Param("regionMaxCode") String regionMaxCode);

    @Select("select distinct REGION_MAX_CODE from ODS_DAT_WINDWIREPOLE202012 where obj_id = #{objId}")
    List<String> getWindRegionCodesDistinctByObjId(@Param("objId") String objId);

    @Select("select distinct REGION_MAX_CODE from ODS_DAT_INSULATOR202012 where obj_id = #{objId}")
    List<String> getPollutionRegionCodesDistinctByObjId(String objId);

    // 由于绝缘子明细只看最高灾害等级的绝缘子情况， 而判断线路污闪的条件是存在任何一个灾害等级不合格，这里无法保证最高灾害等级一定存在绝缘子的爬电比距比标准低10，因此这里不能 -10
    @Select("select * from ODS_DAT_INSULATOR202012 where obj_id = #{objId} and REGION_MAX_CODE = #{regionMaxCode} and pdbj < wqbz ")
    List<Map<String, Object>> getPollutionInsulatorByObjId(String objId, String regionMaxCode);

    //得到老旧的绝缘子
    @Select("select * from ODS_DAT_INSULATOR202012 where obj_id = #{objId} and TUIYISJ < sysdate ")
    List<Map<String, Object>> getOldInsulatorByObjId(String objId);


    /**
     * 查询设备重载
     *
     * @return
     */
    List<TranLoadVO> getTranLoad(@Param("objId")String objId);

    /**
     * 变压器重损
     *
     * @param objId
     * @return
     */
    TranLossVo getTranLossVO(@Param("objId") String objId);

    /**
     * 变压器持续重载
     * @param objId
     * @return
     */
    List<TranLoadAlwaysVO> getTranAlwaysLoad(@Param("objId")String objId);

    /**
     * 线路重载
     */
    LineTranVO getLineTranVO(@Param("objId")String objId);

    /**
     * 输电线路重损
     * @param objId
     * @return
     */
    LineLossVo getLineLossVO(@Param("objId")String objId);

    /**
     * 输电线路持续重载
     * @param objId
     * @return
     */
    List<LineAlwaysLoadVO> getLineAlwaysVo(@Param("objId")String objId);


    /**
     * 配线重载
     * @param objId
     * @return
     */
    DistLineLoadVO getDistLoadVo(@Param("objId")String objId);

    /**
     * 配线重损
     * @param objId
     * @return
     */
    DistLineLossVO getDistLineLossVO(@Param("objId") String objId);

    /**
     * 配线持续重载
     * @param objId
     * @return
     */
    List<DistLineAlwaysLoadVo> getDistLineAlwaysVO(@Param("objId")String objId);

    DistTranLoadVO getDistTranLoadVO(@Param("objId")String objId);

    /**
     * 导线过长
     * @param objId
     * @return
     */
    TooLongLineVO getTooLongLineVo(@Param("objId") String objId);

    /**
     * 导线截面异常
     * @param objId
     * @return
     */
    LineRadiusVO getLineRadiusVO(@Param("objId") String objId);

    /**
     * 高耗能变压器
     * @param objId
     * @return
     */
    HighPowerVO getHighPowerVO(@Param("objId") String objId);

    /**
     * 配变持续重载
     * @param objId
     * @return
     */
    List<DistTranLoadAlwaysVO> getDistTranLoadAlwaysVO(@Param("objId") String objId);

    List<String> getThreeBlanceDate(@Param("objId") String objId);


    List<StatisticsVo> getStatisticsMapByTen(@Param("idList")List<String> idList);
}
